package com.grad.webstudy.controller;

import com.github.pagehelper.PageInfo;
import com.grad.webstudy.annota.LoginAuthorization;
import com.grad.webstudy.context.UserContext;
import com.grad.webstudy.model.History;
import com.grad.webstudy.model.User;
import com.grad.webstudy.service.HistoryService;
import com.grad.webstudy.vo.HistoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: zjf
 * @Date: 2020/2/3 16:15.
 */
@RestController
@RequestMapping("/history")
public class HistoryController {

    @Autowired
    private HistoryService historyService;


    @GetMapping("/queryAllByPage")
    @LoginAuthorization
    public PageInfo queryAllByPage(@RequestParam(defaultValue = "1") int currPage, @RequestParam(defaultValue = "5") int pageSize) {
        return historyService.queryAllByPage(currPage, pageSize);
    }


    @DeleteMapping("/delete")
    @LoginAuthorization
    public boolean deleteHistory(String ids) {
        return historyService.deleteHistories(ids);
    }


    /**
     * 处理历史记录
     *
     * @param courseDetailId
     * @param progress
     * @return
     */
    @PostMapping("/dealHistory")
    @LoginAuthorization
    public boolean dealHistory(Integer courseDetailId, Integer progress) {
        return historyService.userHistory(courseDetailId, progress);
    }


    /**
     * 根据当前用户获取某个视频的进度信息
     * @param courseDetailId
     * @return
     */
    @GetMapping("/getProgress")
    @LoginAuthorization
    public Integer getCourseProgress(Integer courseDetailId){
        User user = UserContext.getLoginUser();
        return historyService.queryCourseDetailHistory(courseDetailId,user.getId()).getProgress();
    }

}
